package behaviorType.visitor;

import java.util.Collection;
import java.util.Iterator;

public class VisitorImpl implements IVisitor {
    // 在本方法中,我们实现了对Collection的元素的成功访问
    @Override
    public void visitCollection(Collection collection) {
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()) {
            Object o = iterator.next();
            if (o instanceof IVisitable)
                ((IVisitable) o).accept(this);
        }
    }

    @Override
    public void visitString(StringElementVisitable stringE) {
        System.out.println("'" + stringE.getValue() + "'");
    }

    @Override
    public void visitFloat(FloatElementVisitable floatE) {
        System.out.println(floatE.getValue().toString() + "f");
    }
}